package com.thtf.strokeinquiry.app.controller;



import com.thtf.strokeinquiry.app.bean.MedInquiryRecord;
import com.thtf.strokeinquiry.app.bean.req.*;
import com.thtf.strokeinquiry.app.bean.resp.CommResponse;
import com.thtf.strokeinquiry.app.service.MedInquiryRecordService;
import com.thtf.strokeinquiry.app.util.DefaultValueUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;



@Controller
@RequestMapping("/inquiry")
public class InquiryController {

    @Autowired
    private MedInquiryRecordService medInquiryRecordService ;


    @ApiOperation(value = "录入基本情况", notes = "录入基本情况")
    @RequestMapping(value = "/saveBasicInformation", method = RequestMethod.POST)
    @ResponseBody
    public CommResponse<MedInquiryRecord> saveBasicInformation(@RequestBody MedPatientInfoReq req){
        MedInquiryRecord data= medInquiryRecordService.saveMedInquiryRecord(req);
        if(data==null){
            return new CommResponse("3001","记录不存在");
        }
        return  new CommResponse(data);
    }

    @ApiOperation(value = "录入调查机构", notes = "录入调查机构")
    @RequestMapping(value = "/saveInquiryOrg", method = RequestMethod.POST)
    @ResponseBody
    public  CommResponse saveInquiryOrg(@RequestBody MedOrgReq req){
        MedOrgReq resp =   medInquiryRecordService.saveInquiryOrg(req);
        if(resp==null){
            return new CommResponse("3001","记录不存在");
        }

        return  new CommResponse(resp);
    }

    @ApiOperation(value = "录入生活方式", notes = "录入生活方式")
    @RequestMapping(value = "/saveLifestyle", method = RequestMethod.POST)
    @ResponseBody
    public  CommResponse saveLifestyle(@RequestBody MedLifestyleReq req){
        if(StringUtils.isEmpty(req.getRecordId())){
           return  null;
        }
        MedLifestyleReq resp=  medInquiryRecordService.saveMedLifeStyle(req);
        if(resp==null){
            return new CommResponse("3001","记录不存在");
        }
        return new CommResponse(req) ;
    }


    @ApiOperation(value = "录入家族史", notes = "录入家族史")
    @RequestMapping(value = "/saveFamilyhistory", method = RequestMethod.POST)
    @ResponseBody
    public  CommResponse saveFamilyhistory(@RequestBody MedFamilyhistoryReq req){
        if(StringUtils.isEmpty(req.getRecordId())){
            return  null;
        }
        MedFamilyhistoryReq resp= medInquiryRecordService.saveFamilyhistory(req);
        if(resp==null){
            return new CommResponse("3001","记录不存在");
        }
        return new CommResponse(req) ;
    }

    @ApiOperation(value = "既往病史及控制情况", notes = "既往病史及控制情况")
    @RequestMapping(value = "/savePrevioushistory", method = RequestMethod.POST)
    @ResponseBody
    public  CommResponse savePrevioushistory(@RequestBody MedPrevioushistoryReq req){
        if(StringUtils.isEmpty(req.getRecordId())){
            return  null;
        }
        MedPrevioushistoryReq resp= medInquiryRecordService.savePrevioushistory(req);
        if(resp==null){
            return new CommResponse("3001","记录不存在");
        }
        return new CommResponse(req) ;
    }

    @ApiOperation(value = "体格检查", notes = "体格检查")
    @RequestMapping(value = "/savePhysicalExam", method = RequestMethod.POST)
    @ResponseBody
    public  CommResponse savePhysicalExam(@RequestBody MedPhysicalexamReq req){
        if(StringUtils.isEmpty(req.getRecordId())){
            return  null;
        }
        MedPhysicalexamReq resp= medInquiryRecordService.savePhysicalExam(req);
        if(resp==null){
            return new CommResponse("3001","记录不存在");
        }
        return new CommResponse(req) ;
    }


    @ApiOperation(value = "心电图", notes = "心电图")
    @RequestMapping(value = "/saveECG", method = RequestMethod.POST)
    @ResponseBody
    public  CommResponse saveECG(@RequestBody MedEcgReq req){
        if(StringUtils.isEmpty(req.getRecordId())){
            return  null;
        }
        MedEcgReq resp= medInquiryRecordService.saveECG(req);

        if(resp==null){
            return new CommResponse("3001","记录不存在");
        }
        return new CommResponse(req) ;
    }



    @ApiOperation(value = "记录实验室检查", notes = "记录实验室检查")
    @RequestMapping(value = "/saveLabinspection", method = RequestMethod.POST)
    @ResponseBody
    public  CommResponse saveLabinspection(@RequestBody MedLabinspectionReq req){
        if(StringUtils.isEmpty(req.getRecordId())){
            return  null;
        }
        MedLabinspectionReq resp= medInquiryRecordService.saveLabinspection(req);

        if(resp==null){
            return new CommResponse("3001","记录不存在");
        }
        return new CommResponse(req) ;
    }

    @ApiOperation(value = "卒中风险", notes = "卒中风险")
    @RequestMapping(value = "/saveRiskass", method = RequestMethod.POST)
    @ResponseBody
    public  CommResponse saveRiskass(@RequestBody MedRiskassReq req){
        if(StringUtils.isEmpty(req.getRecordId())){
            return  null;
        }
        MedRiskassReq resp= medInquiryRecordService.saveMedRiskass(req);
        if(resp==null){
            return new CommResponse("3001","记录不存在");
        }
        return new CommResponse(req) ;
    }


    @ApiOperation(value = "颈部血管超声", notes = "颈部血管超声")
    @RequestMapping(value = "/saveBloodVessels", method = RequestMethod.POST)
    @ResponseBody
    public  CommResponse saveBloodVessels(@RequestBody MedBloodvesselsReq req){
        if(StringUtils.isEmpty(req.getRecordId())){
            return  null;
        }
        MedBloodvesselsReq resp= medInquiryRecordService.saveBloodVessels(req);

        if(resp==null){
            return new CommResponse("3001","记录不存在");
        }
        return new CommResponse(req) ;
    }


    @ApiOperation(value = "血管病变的外科手术或介入治疗情况", notes = "血管病变的外科手术或介入治疗情况")
    @RequestMapping(value = "/saveSurgery", method = RequestMethod.POST)
    @ResponseBody
    public  CommResponse saveSurgery(@RequestBody MedSurgeryReq req){
        if(StringUtils.isEmpty(req.getRecordId())){
            return  null;
        }
        MedSurgeryReq resp=  medInquiryRecordService.saveSurgery(req);

        if(resp==null){
            return new CommResponse("3001","记录不存在");
        }
        return new CommResponse(req) ;
    }


    @ApiOperation(value = "列表接口", notes = "列表接口")
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ResponseBody
    public  CommResponse getList(@RequestParam(required = false) String idNO){
        if(StringUtils.isEmpty(idNO)){
            return  new CommResponse(DefaultValueUtil.getDefaultList());
        }

        return new CommResponse(medInquiryRecordService.getList(idNO)) ;
    }

    @ApiOperation(value = "表单详情", notes = "表单详情")
    @RequestMapping(value = "/getDetil", method = RequestMethod.GET)
    @ResponseBody
    public  CommResponse getDetil(@RequestParam() String recordId,@RequestParam() String type){

        return new CommResponse(medInquiryRecordService.getDetial(recordId,type)) ;
    }

}
